package com.boxin.ims.modules.jiujiudevice.taskthread;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.boxin.ims.modules.jiujiudevice.service.JiuCashRecordService;

/**
 * 定时清除过期订单的线程
 *
 */
@Service
public class DeleteCashOrderThread implements Runnable{
	
	private JiuCashRecordService jiuCashRecordService;
	
	@Autowired
	public DeleteCashOrderThread(JiuCashRecordService jiuCashRecordService){
		this.jiuCashRecordService =jiuCashRecordService;
		if(null != jiuCashRecordService ){
			new Thread(this).start();
		}
	}
	
	
	
	@Override
	public void run() {
		System.err.println("清除过期押金订单的线程已经启动");
		
		while(true){
			System.err.println("清除过期押金订单的线程又开始运行了..");
			//查询所有没有支付的订单  不是全部订单
			int i = jiuCashRecordService.deleteExpiredNoPay();
			System.out.println(String.format("成功删除【%d】条无效押金订单", i));
			try {
				Thread.sleep(1000*60*5);
			} catch (InterruptedException e) {
				System.err.println("清除过期订单的线程被中断");
				e.printStackTrace();
			}
			
		}
		
	}

}
